package com.gsm.controller;

import com.gsm.entity.SysUser;
import com.gsm.service.SysUserService;
import com.gsm.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 后台管理人员账户(SysUser)表控制层
 *
 * @author wjq
 * @since 2020-04-26 21:58:17
 */
@RestController
@RequestMapping("sysUser")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;
    
    /**
     * 新增
     */
    @PostMapping("sysUser")
    public Result insertSysUser(@RequestBody SysUser sysUser) {
        Result result = sysUserService.insertSysUser(sysUser);
        return result;
    }
    
    /**
     * 根据 id 删除数据
     */
    @DeleteMapping("sysUser/{userId}")
    public Result deleteSysUserByUserId(@PathVariable("userId")Long userId) {
        Result result = sysUserService.deleteSysUserByUserId(userId);
        return result;
    }

    /**
     * 根据 id 修改单条数据
     */
    @PutMapping("sysUser/{userId}")
    public Result updateSysUserByUserId(@PathVariable("userId")Long userId, @RequestBody SysUser sysUser) {
        sysUser.setUserId(userId);
        Result result = sysUserService.updateSysUserByUserId(sysUser);
        return result;
    }

    /**
     * 根据 id 查询单条数据
     */
    @GetMapping("sysUser/{userId}")
    public Result selectSysUserByUserId(@PathVariable("userId")Long userId) {
        Result result = sysUserService.selectSysUserByUserId(userId);
        return result;
    }
    
    /**
     * 根据条件查询 List
     */
    @GetMapping("sysUserList")
    public Result selectSysUserList(SysUser sysUser) {
        Result result = sysUserService.selectSysUserList(sysUser);
        return result;
    }
}